package com.sinosoft.brokerchannel.rest;

import com.sinosoft.brokerchannel.base.annotation.MyResponseBody;
import com.sinosoft.brokerchannel.base.common.SystemParamFinal;
import com.sinosoft.brokerchannel.base.rest.AbstractController;
import com.sinosoft.brokerchannel.base.server.LogService;
import com.sinosoft.brokerchannel.base.utile.BusinessException;
import com.sinosoft.brokerchannel.entity.vo.*;
import com.sinosoft.brokerchannel.server.impl.IusServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 需求名称：[保险经纪渠道平台]<br/>
 *
 * @author gzj
 * @version V1.0
 * @date 2018-8-21 10:48
 * B2B个人中心模块
 */
@Api(value = "services", description = "车险渠道平台B2B个人中心模块")
@Controller
@RequestMapping("/person")
public class PersonalCenterController extends AbstractController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private LogService logService;
    @Autowired
    private IusServiceImpl iusService;
    @RequestMapping(value = "messaging", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "短信", notes = "短信")
    @MyResponseBody
    public IusMessagingResponse messaging(@RequestBody IusMessagingRequest request) throws Exception {
        IusMessagingResponse response = new IusMessagingResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("短信", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.messaging(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusMessagingResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
            super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "selectLogistics", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "物流", notes = "物流")
    @MyResponseBody
    public IusLogisticsQueryResponse selectLogistics(@RequestBody IusLogisticsQueryRequest request) throws Exception {
        IusLogisticsQueryResponse response = new IusLogisticsQueryResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.selectLogistics(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusLogisticsQueryResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
           super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "withdrawDeposit", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "提现", notes = "提现")
    @MyResponseBody
    public IusMoneyResponse withdrawDeposit(@RequestBody IusMoneyRequest request) throws Exception {
        IusMoneyResponse response = new IusMoneyResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.withdrawDeposit(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusMoneyResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
           super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "selectGpSettletFee", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "余额查询", notes = "余额查询")
    @MyResponseBody
    public IusSettletFeeResponse selectGpSettletFee(@RequestBody IusSettletFeeRequest request) throws Exception {
        IusSettletFeeResponse response = new IusSettletFeeResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.selectGpSettletFee(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusSettletFeeResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
            super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "selectGuAccount", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "台账查询", notes = "台账查询")
    @MyResponseBody
    public IusAccountResponse selectGuAccount(@RequestBody IusAccountRequest request) throws Exception {
        IusAccountResponse response = new IusAccountResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.selectGuAccount(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusAccountResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
            super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "LedgerSend", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "台账传输", notes = "台账传输")
    @MyResponseBody
    public IusLedgerSendResponse selectGuAccount(@RequestBody IusLedgerSendRequest request) throws Exception {
        IusLedgerSendResponse response = new IusLedgerSendResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.ledgerSend(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusLedgerSendResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
            super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "selectBringOutTheDetails", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "提现明细查询", notes = "提现明细查询")
    @MyResponseBody
    public IusBringOutTheDetailsResponse selectBringOutTheDetails(@RequestBody IusBringOutTheDetailsRequest request) throws Exception {
        IusBringOutTheDetailsResponse response = new IusBringOutTheDetailsResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.selectBringOutTheDetails(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("1".equals(response.getResponseBody().getStatus())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusBringOutTheDetailsResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
           super.afterTheTransaction(response, flowid);
        }
        return response;
    }
    @RequestMapping(value = "selectAchievement", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "业绩查询", notes = "业绩查询")
    @MyResponseBody
    public IusAchievementResponse selectAchievement(@RequestBody IusAchievementRequest request) throws Exception {
        IusAchievementResponse response = new IusAchievementResponse();
        ;//响应对象
        String flowid = "";//交易ID
        try {
            //初始化
            super.init("Ius列表查询", request.getRequestHead());
            //记录日志
            flowid = super.beforeTheTransaction(request);
            //调用服务
            response = iusService.selectAchievement(request);
            //status的状态：1：成功；0：失败；2：暂无数据
            if ("00".equals(response.getResponseBody().getFlag())) {
                super.sucessAction();
            } else {
                super.errorAction(response.getResponseBody().getResultMsg());
            }
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            super.exceptionAction(e);
            logger.info(SystemParamFinal.Exception_LOG, e);
        } finally {
            if (response == null) {
                response = new IusAchievementResponse();
            }
            response.setResponseHead(super.getResponseHead());
            //回写日志
           super.afterTheTransaction(response, flowid);
        }
        return response;
    }
}
